#include <iostream>
#include <queue>

using namespace std; 

typedef pair<int, int> PII;

const int N = 110;
char a[N][N];
bool st[N][N];
int n, m;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};


void dfs(int i, int j)
{
	st[i][j] = true;
	for(int k = 0; k < 8; k++)
	{
		int x = i + dx[k];
		int y = j + dy[k];
		if(x >= 1 && y >= 1 && x <= n && y <= m && a[x][y] == 'W' && st[x][y] == false)
		{
			dfs(x, y);
		}
	}
}
void bfs(int i, int j)
{
	queue<PII> q;
	q.push({i, j});
	st[i][j] = true;
	while(q.size())
	{
		auto t = q.front(); q.pop();
		int x = t.first, y = t.second;
		for(int k = 0; k < 8; k++)
		{
			int ax = x + dx[k];
			int by = y + dy[k];
			if(ax >= 1 && ax <= n && by >= 1 && by <= m && a[ax][by] == 'W' && st[ax][by] == false)
			{
				q.push({ax, by});
				st[ax][by] = true;
			}
		}
	}
}


int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			cin >> a[i][j];
		}
	}
	
	int ret = 0;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			if(a[i][j] == 'W' && st[i][j] == false)
			{
				ret++;
//				dfs(i, j);
				bfs(i, j);
			}
		}
	}
	
	cout << ret << endl;
	
	return 0;
}
